package com.Pratice;

import java.util.Scanner;

public class PREV63 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		boolean flag = false,flag2 = false;
		String a = "",b = "";
		int x = n/10000;
		int y = x%10*1000 + x%100/10*100 + x%1000/100*10 + x/1000; 
		if( y < n%10000)
			x++;
		for(int i = x;i<= 8999;i++) { 
				if( i/100%10 > 3 || i%10 > 1)
					continue;
				if(i%10 == 1 && i/10%10 > 2)
					continue;
				
				int day = i/1000 + i/100%10*10;
				int mouth = i/10%10 + i%10*10;
				
				if(!flag && vertify(mouth,day))
				{
					a = "" + i + format(mouth) + format(day);
					flag = true;
				}
				if(mouth == day && !flag2 && vertify(mouth,day))
				{
					b = "" + i + format(mouth) + format(day);
					flag2 = true;
				}
				if(flag && flag2)
					break;
			}
		System.out.print(a+"\n" + b);
	}
	public static String format(int date) {
		String format = date < 10 ? "0" + date:"" + date;
		return format;
	}
	public static boolean vertify(int mouth,int day)
	{
		switch(mouth){
			case 1:;
			case 3:;
			case 5:;
			case 7:;
			case 8:;
			case 10:;
			case 12:
				if(day < 32)
					return true;
				break;
			case 4:;
			case 6:;
			case 9:;
			case 11:;
				if(day < 31)
					return true;
			break;
			case 2:if(day <= 29)
					return true;
			break;
		}
		return false;
	}
}
